package com.wlyuan.index.controller;

import com.alibaba.fastjson.JSONObject;
import com.wlyuan.index.api.IOrderIndexService;
import com.wlyuan.index.api.dto.order.OrderIndexFilterDTO;
import com.wlyuan.index.api.dto.order.OrderReindexAllDTO;
import com.wlyuan.index.api.dto.order.OrderReindexDTO;
import com.wlyuan.index.api.vo.OrderIndexSumVO;
import com.wlyuan.index.api.vo.OrderIndexVO;
import com.wlyuan.order.api.IOrderService;
import com.wlyuan.tools.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

/**
 * @author yuanjie
 */
@Slf4j
@Api(tags = "订单")
@RestController
@RequestMapping("/order")
public class OrderIndexController {
    @DubboReference(check = false)
    private IOrderIndexService orderIndexService;

    @DubboReference(check = false)
    private IOrderService orderService;

    @ApiOperation("查询索引")
    @GetMapping("/{orderId:\\d+}")
    public OrderIndexVO getIndexById(@PathVariable("orderId") Long orderId) {
        return orderIndexService.getIndexById(orderId);
    }

    @ApiOperation("重建索引")
    @PostMapping("/reindex/{orderId:\\d+}")
    public void reindex(@PathVariable("orderId") Long orderId) {
        orderIndexService.reindex(orderId);
    }

    @ApiOperation("重建索引(筛选)")
    @PostMapping("/reindex")
    public void reindex(@RequestBody OrderReindexDTO reindex) {
        orderIndexService.reindex(reindex);
    }

    @ApiOperation("重建索引(全部)")
    @PostMapping("/reindexAll")
    public void reindexAll(@RequestBody OrderReindexAllDTO reindex) {
        orderIndexService.reindexAll(reindex);
    }

    @ApiOperation("订单列表")
    @PostMapping("/search")
    public Page<OrderIndexVO> search(@RequestBody OrderIndexFilterDTO filter) {
        return orderIndexService.search(filter);
    }

    @ApiOperation("订单统计")
    @PostMapping("/sum")
    public OrderIndexSumVO searchSum(@RequestBody OrderIndexFilterDTO filter) {
        return orderIndexService.searchSum(filter);
    }

    @ApiOperation("索引数据")
    @GetMapping("/insight/{orderId:\\d+}")
    public JSONObject source(@PathVariable("orderId") Long orderId) {
        return orderIndexService.insight(orderId);
    }
}
